home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Kit PC World De Ampliacion De Windows 95
/
Kit PC World de ampliacion de Windows 95.iso
/
clarion
/
gauge
/
gauge.z
/
DSIEVE.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1995-08-24
|
3KB
|
104 lines
unit Dsieve;
interface
uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, StdCtrls, Clipbrd, DdeMan;
const
Cycles = 2000; {Number of cycles}
ArraySize = 1000; {Array size}
type
TSieve = class(TForm)
Label1: TLabel;
Run: TButton;
Exit: TButton;
Label2: TLabel;
CyclesPerMinute: TLabel;
DdeServerItem1: TDdeServerItem;
DPSIEVE: TDdeServerConv;
procedure RunClick(Sender: TObject);
procedure ExitClick(Sender: TObject);
procedure DDEOpen(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Sieve: TSieve;
Start: LongInt;
Stop: LongInt;
CycsPerMin: Real;
procedure RunSieve;
implementation
{$R *.DFM}
procedure TSieve.RunClick(Sender: TObject);
begin
Start := GetTickCount;
Run.Enabled := False;
Exit.Enabled := False;
Screen.Cursor := crHourglass;
RunSieve;
Stop := GetTickCount;
CycsPerMin := Cycles * 60000 / (Stop - Start);
CyclesPerMinute.Caption := Format( '%10.0n',[CycsPerMin]);
ClipBoard.Clear;
ClipBoard.AsText := Format( '%10f',[CycsPerMin]);
Run.Enabled := True;
Exit.Enabled := True;
Screen.Cursor := crDefault;
end;
procedure TSieve.ExitClick(Sender: TObject);
begin
Sieve.Close;
end;
procedure RunSieve;
var
Flag: Array[1..ArraySize] of Byte; {Array of flags}
Prime: Integer; {Next prime}
I: Integer; {Loop counter}
K: Integer; {Step size}
Cycle: Integer; {Cycle number}
Count: Integer; {Number of primes}
Begin
For Cycle := 1 to Cycles Do {Do multiple iterations}
Begin
Count := 0; {Clear prime counter}
For I := 1 To ArraySize Do Flag[I] := 1; {Clear array}
For I := 1 To ArraySize Do {Sift out the non-primes}
Begin
IF Flag[I] = 1 Then {For flags that are on}
Begin
Prime := I + I + 1; { Set the next prime}
K := I + Prime; { Set step count}
While K <= ArraySize Do { Loop through remainder}
Begin
Flag[K] := 0; { Turning off flags}
K := K + Prime; { Jump to next step}
End;
Count := Count + 1;
End; { Increment prime counter}
End; { End the IF}
End; {End the outside LOOP}
End;
procedure TSieve.DDEOpen(Sender: TObject);
begin
Sieve.RunClick(Sender);
Sieve.ExitClick(Sender);
end;
End.